package dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/9/25 15:49
 * @Description: 连接数据库
 */
public class LoginInfoDao {

  private QueryRunner runner;
  private static final ComboPooledDataSource ds = new ComboPooledDataSource();

  public LoginInfoDao() {
    runner = new QueryRunner(ds);
  }

  /**
   * 获取当前的记录情况
   * @param id
   * @return
   * @throws SQLException
   */
  public int getCountById(int id) throws SQLException {
    LoginInfoTmp tmp = runner.query("select count from logininfotmp where id = ?",
        new BeanHandler<LoginInfoTmp>(LoginInfoTmp.class), id);

    return tmp.getCount();
  }

  /**
   * 更新登录数据
   * @param id
   * @param count
   * @throws SQLException
   */
  public void saveCountById(int id, int count) throws SQLException {
    runner.update("update logininfotmp set count = ? where id = ?", count, id);
  }
}
